package com.huifaapp.mall.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.huifaapp.mall.R;
import com.huifaapp.mall.adapter.HotSearchClassifyViewPagerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/1/26.
 */

public class SearActivity extends AppCompatActivity{
    private TabLayout classifyTL;
    private ViewPager classifyVP;
    private List<HotSearchFragment> hotSearchFragments = new ArrayList<>();
    private TextView search;
    private EditText search_input_et;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.hide();
        }
        initView();
        initAdapter();
    }

    private void initAdapter() {
        //创建Fragment
        HotSearchFragment jDHSF = new HotSearchFragment("京东");
        HotSearchFragment yHHSF = new HotSearchFragment("友惠");
        HotSearchFragment totalHSF = new HotSearchFragment("全部");
        //为fragment集合添加数据
        hotSearchFragments.add(totalHSF);
        hotSearchFragments.add(jDHSF);
        hotSearchFragments.add(yHHSF);

        HotSearchClassifyViewPagerAdapter hotSearchClassifyViewPagerAdapter =
                new HotSearchClassifyViewPagerAdapter(getSupportFragmentManager(),hotSearchFragments);
        classifyVP.setAdapter(hotSearchClassifyViewPagerAdapter);
        classifyTL.setupWithViewPager(classifyVP);
        classifyTL.setTabMode(TabLayout.MODE_FIXED);
    }

    private void initView() {
        classifyVP = (ViewPager) findViewById(R.id.classify_vp);
        classifyTL = (TabLayout) findViewById(R.id.classify_tl);
        search = (TextView) findViewById(R.id.search);
        search_input_et = (EditText) findViewById(R.id.search_input_et);
        search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(SearActivity.this,Search_showActivity.class);
                intent.putExtra("keyword",search_input_et.getText().toString());
                intent.putExtra("titlename","查看列表");
                startActivity(intent);
            }
        });
    }

}
